/*
 * Created on 02-may-2004
 * 
 * TODO To change the template for this generated file go to Window -
 * Preferences - Java - Code Generation - Code and Comments
 */
package core.loaders.io;

import java.io.BufferedWriter;
import java.io.FileWriter;

/**
 * @author Norvin Altamirano Ruiz the file writer.
 */
public class GameFileWriter {
	private BufferedWriter buffer;

	private String filename;

	/**
	 * constructor.
	 * 
	 * @param name
	 */
	public GameFileWriter(String name) {
		filename = name;
	}

	/**
	 * opens the file returns true if all is correct.
	 * 
	 * @return
	 * 
	 * @see
	 */
	public boolean openFile() {
		boolean correct = false;
		try {
			FileWriter fw = new FileWriter(getName());
			buffer = new BufferedWriter(fw);
			correct = true;
		} catch (Exception x) {
			x.printStackTrace();
			correct = false;
		}
		return correct;
	}

	/**
	 * writes a character in a file.
	 * 
	 * @param
	 * 
	 * @see
	 */
	public void write(char character) {
		try {
			buffer.write(character);
		} catch (Exception x) {
			x.printStackTrace();
		}
	}

	/**
	 * writes a string in a file.
	 * 
	 * @param
	 * 
	 * @see
	 */
	public void write(String string) {
		try {
			buffer.write(string);
		} catch (Exception x) {
			x.printStackTrace();
		}
	}

	/**
	 * makes a newline.
	 * 
	 * @see
	 */
	public void newLine() {
		try {
			buffer.newLine();
		} catch (Exception x) {
			x.printStackTrace();
		}
	}

	/**
	 * closes the file returns true if all is correct.
	 * 
	 * @see
	 * @return
	 */
	public boolean closeFile() {
		boolean correct = false;
		try {
			buffer.close();
			correct = true;
		} catch (Exception x) {
			x.printStackTrace();
		}
		return correct;
	}

	/**
	 * returns the filename.
	 * 
	 * @return
	 * 
	 * @see
	 */
	public String getName() {
		return filename;
	}
}